$(function(){
	
	dataInit();
});

function dataInit() {
	
	//设备详情
	var device = getDeviceById($("#deviceId").val());
	var contract = getContractById($("#contractId").val());
	var deviceDetailHtml = '不合法的参数,<span id="count">5</span>秒后返回<a href="../index.jsp">首页</a>';
	if (device != 'null' && contract != 'null') {
		
		deviceDetailHtml =  '<div class="col-lg-6 align-self-center g-mb-60">'
							+		'<img class="img-fluid" src="'+device.deviceImageUrl+'" alt="Image Description">'
							+	'</div>'
	
							+	'<div class="col-lg-6 align-self-center g-mb-60">'
							+	'<div class="mb-2">'
							+	'<h2 class="h3 g-color-black text-uppercase mb-2">'+device.deviceName+'</h2>'
							+	'<div class="d-inline-block g-width-35 g-height-2 g-bg-primary mb-2"></div>'
							+	'</div>'
							+	'<div class="mb-5">'
							+	'<p class="mb-5">'+device.deviceDesc+'</p>'
	
							+	'<ul class="list-unstyled g-font-size-13 mb-0">';
		$.ajax({
			url:"../deviceAttr/query.action",
			type: "post",
			data: {"deviceId":device.id, "attrStatus":"1"},
			async: false,
			success: function(data) {
				$(data).each(function(){
					deviceDetailHtml += '<li>'
									+		'<i class="d-inline-block g-color-primary mr-2 mb-3 fa fa-circle"></i>'
									+		getAttrNameName(this.attrNameId)+'：'+this.attrValue+'</p>'
									+	'</li>';
				});
			}
		});
		deviceDetailHtml +=		'</ul>'
							+	'</div>'
							+	'<a class="btn btn-md u-btn-outline-black g-font-size-default g-rounded-50 g-py-10 mr-2" href="../bill/form.action?contractId='+contract.id+'">我要报修</a>'
							+	'</div>';
	} else {
		countDown(5);
	}
	$("#deviceDetailInfo").html(deviceDetailHtml);
}

function countDown(second) {
	if (second != 0) {
		$("#count").text(second);
		setTimeout('countDown('+(second-1)+')',1000)
	} else {
		window.location.href="../index.jsp";
	}
}


